<?php
/*
 * 	Yamp52 - Yet Another Magical PHP framework
 *	http://code.google.com/p/yamp52/
 *	
 *	Copyright (C) 2009, Krzysztof Drezewski <krzych@krzych.eu>
 *	
 *	This program is free software; you can redistribute it and/or modify
 *	it under the terms of the GNU General Public License as published by
 *	the Free Software Foundation; either version 3 of the License, or
 *	(at your option) any later version.
 *	
 *	This program is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *	GNU General Public License for more details.
 *	
 *	You should have received a copy of the GNU General Public License
 *	along with this program. If not, see <http://www.gnu.org/licenses/>.
 */


function smarty_function_tip($args, &$SMARTY) {
	
	$offsetx = ($args['offsetx'])?($args['offsetx']) : 5;
	$offsety = ($args['offsety'])?($args['offsety']) : 5;
	$width = ($args['width'])?($args['width']) : 150;
	$height = ($args['height'])?($args['height']) : -1;
	$textsize = ($args['textsize'])?($args['textsize']) : 1;

	
	
        $allVars = $SMARTY->getTemplateVars('error');
        $err = $allVars[$args['trigger']];
	if($err instanceof Message) {
		$error = $err->getMsg();
		$status = $err->getStatus();
		switch($status) {
			case MESSAGE_ERR:
				$class = 'class="err"';
				break;
			case MESSAGE_WARN:
				$class = 'class="warn"';
				break;
			case MESSAGE_OK:
				$class = 'class="ok"';
				break;
			default:
				$class = 'class="err"';
		}
	}
	
	$error = str_replace("'",'\\\'',$error);
	$error = str_replace('"','&quot;',$error);
	$error = str_replace("\r",'',$error);
	$error = str_replace("\n",'<BR>',$error);

	$text = str_replace('\'','\\\'',$args['text']);
	$text = str_replace('"','&quot;',$text);
	$text = str_replace("\r",'',$text);
	$text = str_replace("\n",'<BR>',$text);

	
	if($error) {
		$result = $class.' onMouseOver="return overlib(\'<B><FONT COLOR=RED>'.$error.'</FONT></B>\',HAUTO,VAUTO,OFFSETX,'.$offsetx.',OFFSETY,'.$offsety.',WIDTH,'.$width.',HEIGHT,'.$height.',TEXTSIZE,'.$textsize.');" onMouseOut="nd();" ';
	} elseif($args['text'] != "") {
		$result = 'onMouseOver="return overlib(\''.$text.'\',HAUTO,VAUTO,OFFSETX,'.$offsetx.',OFFSETY,'.$offsety.',WIDTH,'.$width.',HEIGHT,'.$height.',TEXTSIZE,'.$textsize.');" onMouseOut="nd();"';
	}
	return $result;
}
?>